<?php 
namespace Home\Controller;
use Think\Controller;

class UserController extends Controller
{

	public function regist()
	{
		$this->display();
	}

	/**
	 * [queryUserCon 验证注册用户输入的用户名
	 * 	是否存在及是否合法]
	 * 
	 */
	public function queryUserCon()
	{
		$user = D('user');
		$result = $user->queryUser();
	    $this->ajaxReturn($result);
	}


	/**
	 * [queryEmailCon 方法验证用户输入的邮箱是否合法
	 * 	 及是否已经被注册过]
	 * @return [type] [description]
	 */
	public function queryEmailCon()
	{
		$user = D('user');
		$resEmail = $user->queryEmail();
		$this->ajaxReturn($resEmail);
	}

	/**
	 * [queryRegCon 方法验证用户输入的验证码是否正确]
	 * @return [type] [description]
	 */
	public function queryRegCon()
	{
		$code = I('post.code');
		$verify = new \Think\Verify();
		$bool = $verify->check($code);

		if(!$bool){
			$this->error('验证码错误');
		}


		$user = D('user');
		$userReg = $user->queryReg();
		if($userReg == "注册成功！请重新登录"){
			$this->success($userReg,U('Home/login/index'),2);
		}else{
			$this->error($userReg,U('Home/User/Regist'),2);
		}
	}

	/**
	 * [verify_code 调用TP的验证码函数]
	 * @return [type] [description]
	 */
	public function verify_code()
    {
    	$Verify = new \Think\Verify();
    	$Verify->fontSize = 18;
    	$Verify->length   = 4;  
	    $Verify->useNoise = false;  
	    $Verify->codeSet = 'qwertyuioplkjhgfdsazxcvbnm';  
	    $Verify->imageW = 130;  
	    $Verify->imageH = 50;  
	    $Verify->entry();
    }
    
}